home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / A.D. Software / OOFILE / Buildable, limited OOFILE / samples / ooftst06.cpp < prev    next >
C/C++ Source or Header  |  1996-03-25  |  2KB  |  74 lines

  1. // Copyright 1994 A.D. Software. All Rights Reserved
  2.  
  3. // OOFTEST6
  4.  
  5. // this sample modifies related data
  6. // including demonstrating the caching of related records
  7. // as would typically be used in a GUI environment
  8.  
  9. // Simple stream I/O is used to interact with the user.
  10. #include "oofile.hpp"
  11.  
  12.  
  13. #include "ooftst02.inc"
  14. // included in ooftst2, 3, 4, 6, 9 & 15
  15.  
  16. int main()
  17. {
  18.     cout << "OOFILE Validation Suite - Test 6\n"
  19.          << "Simple test to demonstrate updating related fields" << endl
  20.          << "using the database from ooftst02" << endl;
  21.  
  22.     if (dbConnect::fileExists("ooftst06.db")) {
  23.         theDB.openConnection("ooftst06.db");
  24.         Patients.deleteAll();
  25.     }
  26.     else {
  27.         theDB.newConnection("ooftst06.db");
  28.     }
  29.     Patients.AddTestData();
  30.  
  31.     dbView smithVisits(Patients.Visits); 
  32.     smithVisits << Patients.Visits->VisitDate << Patients.Visits->Why; 
  33.  
  34.     Patients.search(Patients.LastName=="Smith");
  35.     cout << "Dumping Smith and his visits: " << endl 
  36.          << Patients << endl 
  37.          << smithVisits << endl;
  38.  
  39.     cout << "changing the first reason to 'Computer-Induced Sanity' " << endl;
  40.     Patients.Visits->gotoRecord(0);
  41.     Patients.Visits->Why = "Computer-Induced Sanity";
  42.     
  43.     cout << "changing the second reason to 'Funny Views' " << endl;
  44.     smithVisits.source()->gotoRecord(1);  // test navigating via the view
  45.     smithVisits.field(1) = "Funny Views";
  46.  
  47.     Patients.saveRecord();  // save both changes
  48.  
  49.     cout << "Dumping Smith and changed visits: " << endl 
  50.          << Patients << endl 
  51.          << smithVisits << endl;
  52.  
  53.     Patients.AddVisit("14/2/1995", "Anxiety Attacks");
  54.     
  55. // now change to another related record - our new one should be cached
  56.     smithVisits.source()->gotoRecord(1);  
  57.     smithVisits.field(1) = "Changed Again";
  58.  
  59. // return to the new record (in the cache) and update it    
  60.     smithVisits.source()->gotoRecord(2);  
  61.     smithVisits.field(0) = "15/2/1994";
  62.     
  63.     Patients.saveRecord(); 
  64.  
  65.     cout << "Dumping Smith and visits with added visit: " << endl 
  66.          << Patients << endl 
  67.          << smithVisits << endl;
  68.          
  69.     cout << "Now dumping the entire Visits file: " << endl << Visits;
  70.  
  71.     cout << "done" << endl;
  72.     
  73.     return EXIT_SUCCESS;
  74. }